﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using WebUI.Models;
using WebUI.Utils;
using Utils;

namespace WebUI.Infrastructure
{
    public class LoginRoleProvider : RoleProvider
    {
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            throw new NotImplementedException();
        }

        public override string[] GetRolesForUser(string username)
        {
            List<string> roles = new List<string>();
            UserIdentityModel identity = ViewModelUtils.CreateUserIdentityModel(false);
            if (identity.IsLoggedIn)
            {
                string accountType = identity.AccountType; //SqlUtilities.Query<string>(ConstUtils.SP_GetAccountType, new { LoginID = identity.LoginID}).First();
                if (accountType == "i")
                {
                    roles.Add(RoleNames.Individual);
                }
                else if (accountType == "c")
                {
                    roles.Add(RoleNames.Company);
                }
                else {
                    roles.Add(RoleNames.Guest);
                }
            }
            else
            {
                roles.Add(RoleNames.Guest);
            }

            return roles.ToArray();
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool IsUserInRole(string username, string roleName)
        {
            throw new NotImplementedException();
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }
    }
}